<style scoped>
.wraper {
    padding: 0 20px;
}

.search-form{
    overflow: hidden;
}
.search {
    padding-bottom: 20px;
}

.search span {
    color: #68777c;
    font-weight: bold;
    padding-right: 18px;
}

.search button {
    background-color: #00a8f7;
    color: #fff;
    margin-left: 8px;
}

.top {
    margin-bottom: 20px;
    border-top: 1px dashed #cccccc;
}


.wraper .headline {
    position: relative;
    font-size: 12px;
    color: #303134;
    font-weight: bold;
    margin: 10px 0;
    line-height: 32px;
}

.wraper .add-agent {
    position: absolute;
    top: 0px;
    right: 30px;
    background-color: #348bf2;
    color: #fff;
}

.iconfont {
    font-size: 14px;
}

.red-font {
    color: #ff1f1f;
}




.fixed-bottom{
    padding-left: 20px;
    padding-right: 20px;
    height: 80px;
    line-height: normal !important;
    position: fixed;
    left: 210px;
    right: 0;
    bottom: 0;
    z-index: 999;
    text-align: center;
    background-color: rgb(255, 255, 255);
    box-shadow: 0px 0px 9px 0px rgba(0, 0, 0, 0.28);
}
.sidehide{
    left: 75px;
}


/* 表格样式 start*/

.pro-card {
    margin-bottom: 10px;
}

.pro-card-head {
    background-color: #e6e7eb;
    line-height: 38px;
    border: 1px solid #ddd;
}

.pro-card-title {
    font-size: 14px;
    color: #333;
    font-weight: bold;
    padding-left: 20px;
}

.pro-card-headr {
    padding-right: 10px;
    text-align: right;
}

.pro-card-content {
    clear: both;
}

.pro-paramname {
    text-align: center;
    background-color: #e6e7eb;
    font-size: 14px;
    color: #333;
    border-right: 1px solid #ddd;
}

.pro-paramvalue {
    padding-left: 10px;
    border-right: 1px solid #ddd;
    overflow: hidden;
    white-space: nowrap;
    text-overflow:ellipsis;
}

.pro-card-contentrow {
    line-height: 40px;
    border-left: 1px solid #ddd;
    border-bottom: 1px solid #ddd;
}






/* 表格样式  end */


/* 分页 start */

.page {
    margin:  0;
}

.ivu-page {
    padding-bottom: 150px;
}







/* 分页 end */

.receiptbox{
    padding: 10px;
    background-color: #edf2f6;
}

.receiptbox .ivu-input-group-append button{
    background-color: #19be6b;
    color: #fff;
}
.receiptbox .ivu-input-group{
    top: 0;
}
.receiptbox-upload{
    position: relative;
}
.receiptbox-upload-input{
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    opacity: 0;
    cursor: pointer;
}
.receiptbox .ivu-tag{
    vertical-align: middle;
}
.renewal-box{
    margin-left: -16px;
    margin-right: -16px;
    padding: 16px;
    padding-bottom: 0;
    background-color: #cfebf9;
    overflow: hidden;
}
.renewal-pro{
    margin-left: -16px;
    margin-right: -16px;
    padding: 12px;
    height: 395px;
    overflow-y: auto;
}
.renewal-pro-title{
    padding-left: 15px;
    height: 50px;
    line-height: 50px;
    font-size: 16px;
    background-color: #edf2f6;
    margin-bottom: 10px;
}
.renewal-pro-title b{
    display: inline-block;
    margin-left: 20px;
}
.renewal-pro-checkbox{
    font-size: 14px;
    padding-left: 15px;
    border: 1px solid #edf2f6;
    height: 50px;
    line-height: 50px;
    margin-bottom: 10px;
}
.renewal-pro-price{
    color: #ff4848;
    font-size: 16px;
    padding-right: 15px;
}
.renewal-footer{
    margin: -12px -18px;
    padding: 12px 18px;
    background-color: #f2f2f2;
    overflow: hidden;
}
.renewal-footer-l{
    float: left;
}
.renewal-footer-r{
    float: right;
}
.renewal-total{
    padding-left: 15px;
    color: #ff3d3d;
    font-size: 25px;
}
</style>
<style>
.a-link{
    color: #4074e1;
    text-decoration: underline;
    cursor: pointer;
}
.ivu-table-row-highlight .a-link{
    color:#fff;
}
.receiptbox .ivu-tag span.ivu-tag-text{
    max-width:260px;
    overflow: hidden !important;
    display: inline-block;
    text-overflow:ellipsis;
    white-space:nowrap;
    vertical-align: middle;
}
.receiptbox .ivu-tag span.ivu-tag-dot-inner,.receiptbox .ivu-tag i{
    vertical-align: middle;
}
</style>



<template>
    <div class="policy-manage">
        <product-title></product-title>
        <div class="wraper">        
            <div class="pro-con-f common-box-body">
                <Row>
                    <h3 class="search-h3 huang" >
                        快速搜索
                    </h3>
                        <Form  :model="searchForm" class="search-form">
                            <Col :xs="24" :sm="12" :md="12" :lg="7">
                                <FormItem  label="选择公司">
                                    <!-- <Select v-model="searchForm.cid"  filterable  placeholder="选择保险公司" :transfer=true>  
                                        <Option v-for="(option, index) in comoptions" :value="option.cid" :key="index">{{option.name}}</Option>                               
                                    </Select> -->
                                    <Select v-model="searchForm.policy_cid" multiple filterable  placeholder="选择保险公司" :transfer=true> 
                                        <Option v-for="(option, index) in comoptions" :value="option.cid" :key="index">{{option.name}}</Option>                               
                                    </Select>
                                </FormItem>
                            </Col>
                            <Col :xs="24" :sm="12" :md="12" :lg="7">
                                <Form-item label="选择机构">
                                    <!-- <Select ref="orgselect"  label-in-value :label="oname" filterable remote @on-change="orgchange($event)" :remote-method="oidremote" :loading="remoteloading" placeholder="请输入分支机构" v-model="searchForm.yun_org_mid" :transfer=true>
                                        <Option v-for="item in orglist" :value="item.value" :key="item.value">{{item.label}}</Option>                                                                                                                                       
                                    </Select> -->
                                    <Select ref="orgselect"  filterable  placeholder="请输入分支机构" v-model="searchForm.yun_org_mid" :transfer=true>
                                        <Option value="0">全部</Option>
                                        <Option v-for="item in orglist" :value="item.id" :key="item.id">{{item.shortn}}</Option>                                                                                                                                       
                                    </Select>
                                </Form-item>
                            </Col>
                            <Col :xs="24" :sm="12" :md="12" :lg="7">
                                <Form-item label="保单状态">           
                                    <Select v-model="searchForm.status" label-in-value :label="aname" transfer    placeholder="请选择">  
                                        <Option value="0">全部</Option>
                                        <Option value="1">预收件</Option>
                                        <Option value="2">承保件</Option>
                                        <Option value="3">契撤件</Option>
                                        <Option value="4">停效件</Option>
                                        <Option value="5">失效件</Option>
                                        <Option value="6">解约件</Option>
                                        <Option value="7">终止件</Option>
                                    </Select>
                                </Form-item>
                            </Col>

                            <Col :xs="24" :sm="12" :md="12" :lg="7">
                                <Form-item>
                                    <Select v-model="searchForm.type" transfer style="width:120px;float:left;">
                                        <Option value="insure_date">投保时间</Option>
                                        <Option value="underwrite_date">承保时间</Option>
                                        <Option value="effect_date">生效日期</Option>
                                        <Option value="receipt_date">回执时间</Option>
                                        <Option value="visit_date">回访时间</Option>
                                        <Option value="withdraw_date">撤单时间</Option>
                                        <Option value="terminal_date">终止时间</Option>
                                    </Select>
                                    <DatePicker style="margin-left:120px;" @on-change="datachange($event,searchForm,'daterange')" v-model="searchForm.daterangetime" type="daterange" transfer placeholder="请选择" ></DatePicker>
                                </Form-item>
                            </Col>
                            
                            <Col :xs="24" :sm="12" :md="12" :lg="7">
                                <Form-item label="投保人">
                                    <Input size="large" type="text"  v-model="searchForm.appName" placeholder="投保人" />
                                </Form-item>
                            </Col>
                            
                            <Col :xs="24" :sm="12" :md="12" :lg="7">
                                <Form-item label="业务员">           
                                    <Select v-model="searchForm.agent_name" label-in-value :label="aname" @on-change="agentchange($event)" transfer  filterable remote  :remote-method="remoteemployee" :loading="proloading"  placeholder="选择业务员">  
                                        <Option v-for="(option, index) in employeelist" :value="option.label" :key="index">{{option.label}}</Option>                               
                                    </Select>
                                </Form-item>
                            </Col>
                            <Col :xs="24" :sm="24" :md="24" :lg="3" >
                                <Form-item  style="padding-right:0px;">
                                    <Button size="large"  class="fr" type="info" icon="ios-search" @click="search">搜索</Button>
                                </Form-item>
                            </Col>
                            <div class="clear"></div>
                        </Form>
                        <Col span="24" class="table-action" >
                            <Button type="success" size="large" class="fr" icon="plus"  @click="createPloicy">新增</Button>
                            <div style="border-right: 1px solid #EDF2F6;padding-right: 15px;margin-right: 15px;" class="fr">                                
                                <Upload action="" :before-upload="handleUpload" name="file_input" accept="text/csv" :format="['csv']">
                                    <Button type="warning" size="large" class="fr" icon="icon iconfont icon-riqi" >导入数据</Button>
                                </Upload>
                            </div>
                        </Col>
                </Row>
            </div>
            <div class="detail">
                <div class="clearfix">
                    <div class="table-theme">
                        <Table :loading="tableloading" ref="currentRowTable" @on-current-change="tableCurrentChange($event)" size="large" stripe highlight-row border :columns="columns1" :data="policylist" class=""></Table>
                    </div>                        
                </div>
            </div>
        </div>
        <div :class="slidetoggle?'fixed-bottom':'fixed-bottom sidehide' ">
            <Row class="pro-pagesize">
                <Col :sm="24" :md="12" :lg="14">
                    <!-- <Button type="error" :disabled="tableaction" @click="policyDel" size="large" class="fl mr10 ">删除</Button> -->
                    <Button type="primary" :disabled="tableaction" @click="policyEdit" size="large" class="fl mr10">编辑</Button>
                    <Button type="success" :disabled="tableaction" @click="policyUnderwriteBtn" size="large" class="fl mr10">承保</Button>
                    <Button type="primary" :disabled="tableaction" @click="policyeffectBtn" size="large" class="fl mr10">合同生效</Button>
                    <Button type="success" :disabled="tableaction" @click="policyReceiptBtn" size="large" class="fl mr10">回执</Button>
                    <Button type="warning" :disabled="tableaction" @click="policyVisitBtn" size="large" class="fl mr10">回访</Button>
                    
                </Col>
                <Col :sm="24" :md="12" :lg="10" class="tRight">
                    <Page ref="pages" :current="currentpage" :total="listTotal" show-total show-sizer :page-size="pagesize" @on-change="pageChange" @on-page-size-change="pageSizeChange" placement="top" class="page"></Page>
                </Col>
            </Row>
        </div>
        <!-- 合同生效时间 -->
        <Modal v-model="effectModal" :mask-closable='closeable' width="600" title="合同生效" @on-ok="effectok" :loading="loading">
            <Row class="common-box-body">
                <Col span="18" offset="3">                
                    <Form :model="effect" ref="effect"  :rules="effectValidate">                                     
                        <Form-item label="合同生效时间" prop="effect_datetime">
                            <DatePicker type="date" v-model="effect.effect_datetime" @on-change="datachange($event,effect,'effect_date')"  placeholder="选择合同生效时间"></DatePicker>
                        </Form-item>
                    </Form>
                </Col>
            </Row>
        </Modal>
        <!-- 回访时间 -->
        <Modal v-model="revisitModal" :mask-closable='closeable' width="600" title="回访" @on-ok="visitInsure" :loading="loading">
            <Row class="common-box-body">
                <Col span="18" offset="3">                
                    <Form :model="revisitInsure"  :rules="ruleValidate">                                     
                        <Form-item label="回访时间" prop="visit_datetime">
                            <DatePicker type="date" v-model="revisitInsure.visit_datetime" @on-change="datachange($event,revisitInsure,'visit_date')"  placeholder="选择回访时间"></DatePicker>
                        </Form-item>
                    </Form>
                </Col>
            </Row>
        </Modal>
        <!-- <Modal v-model="renewalModal" :mask-closable='closeable' width="600" title="续期管理"  :loading="loading">
            <div class="modal-body">            
                <Row>
                    <Col span="24">
                        <div class="import-left">
                            <div class="common-box-body">
                                <div class="import-search">
                                    <Form ref="formInline">
                                        <Form-item label="姓名">
                                            <Input placeholder="请输入姓名" v-model="searchemploy">
                                                <Button slot="append" @click="searchemp" type="primary" icon="icon iconfont icon-sousuo"></Button>
                                            </Input>
                                        </Form-item> 
                                    </Form>
                                </div> 
                                <div class="import-list">
                                    <Table :loading="tableloading" :show-header=false stripe height="415" :columns="columns" :data="emplist"></Table>
                                </div>                             
                            </div>
                        </div> 
                    </Col>
                </Row> 
            </div>                      
            <div slot="footer"></div>          
        </Modal>  -->
        <!-- 续期 -->
        <Modal v-model="renewalModal" :mask-closable='closeable' width="600" title="续期管理"  :loading="loading">
            <Row class="common-box-body">
                <div class="renewal-box">
                    <Form :model="renewalInsure">
                        <Col span="8">                                                                             
                            <Form-item >
                                <Select placeholder="保险年度" transfer>
                                <Option value="1">第一年</Option>
                                <Option value="2">第二年</Option>
                                <Option value="3">第三年</Option>
                                </Select>
                            </Form-item>                        
                        </Col>
                        <Col span="8">                                                                           
                            <Form-item>
                                <Select placeholder="保险次数" transfer>
                                <Option value="1">第一年</Option>
                                <Option value="2">第二年</Option>
                                <Option value="3">第三年</Option>
                                </Select>
                            </Form-item>                        
                        </Col>
                        <Col span="8">                                                                          
                            <Form-item>
                                <DatePicker transfer type="date" v-model="renewalInsure.visit_datetime" @on-change="datachange($event,renewalInsure,'visit_date')"  placeholder="选择交费时间"></DatePicker>
                            </Form-item>                        
                        </Col>
                        <Col span="24">                                                                          
                            <Form-item label="备注">
                                <Input placeholder=""></Input>
                            </Form-item>                        
                        </Col>
                    </Form>
                </div>
                <div class="renewal-pro">
                    <div class="renewal-pro-title">
                        被保人  <b>李月珍</b>
                    </div>                    
                    <CheckboxGroup>
                        <div class="renewal-pro-checkbox">
                            <Checkbox size="large">
                                附加如意宝住院费用医疗80%
                            </Checkbox>
                            <div class="fr renewal-pro-price">
                                ￥:364.00
                            </div>
                        </div>
                        <div class="renewal-pro-checkbox">
                            <Checkbox size="large">
                                附加如意宝住院费用医疗80%
                            </Checkbox>
                            <div class="fr renewal-pro-price">
                                ￥:364.00
                            </div>
                        </div>
                        <div class="renewal-pro-checkbox">
                            <Checkbox size="large">
                                附加如意宝住院费用医疗80%
                            </Checkbox>
                            <div class="fr renewal-pro-price">
                                ￥:364.00
                            </div>
                        </div>
                    </CheckboxGroup>
                    <div class="renewal-pro-title">
                        被保人  <b>李月珍</b>
                    </div>                    
                    <CheckboxGroup>
                        <div class="renewal-pro-checkbox">
                            <Checkbox size="large">
                                附加如意宝住院费用医疗80%
                            </Checkbox>
                            <div class="fr renewal-pro-price">
                                ￥:364.00
                            </div>
                        </div>
                        <div class="renewal-pro-checkbox">
                            <Checkbox size="large">
                                附加如意宝住院费用医疗80%
                            </Checkbox>
                            <div class="fr renewal-pro-price">
                                ￥:364.00
                            </div>
                        </div>
                        <div class="renewal-pro-checkbox">
                            <Checkbox size="large">
                                附加如意宝住院费用医疗80%
                            </Checkbox>
                            <div class="fr renewal-pro-price">
                                ￥:364.00
                            </div>
                        </div>
                    </CheckboxGroup>
                </div>              
            </Row>
            <div slot="footer" class="renewal-footer">
                <div class="renewal-footer-l">总计 <span class="renewal-total">68165.48</span></div>
                <div class="renewal-footer-r">
                    <Button type="primary"  @click="policyEdit" size="large" class="fl mr10">确定</Button>
                    <Button type="ghost" @click="policyEdit" size="large" class="fl">取消</Button>
                </div>
            </div>
        </Modal>
        <!-- 回执 -->
        <Modal v-model="receiptModal" :mask-closable='closeable' title="回执" @on-ok="receiptok" :loading="loading">
            <Row class="common-box-body">
                <Col span="18" offset="3">                
                    <Form :model="receiptform" ref="receiptform" :rules="receiptValidate">                                     
                        <Form-item label="回执时间" prop="receipt_datetime">
                            <DatePicker type="date" v-model="receiptform.receipt_datetime" @on-change="datachange($event,receiptform,'receipt_date')"  placeholder="选择回执时间"></DatePicker>
                        </Form-item>
                        <div class="receiptbox">
                            <Form-item label="影像文档">
                                <Input type="text" disabled>
                                    <div slot="append" class="receiptbox-upload">
                                        <input type="file" class="receiptbox-upload-input" @change="uploadChange($event)">
                                        <Button  icon="plus">上传附件</Button>
                                    </div>    
                                </Input>
                            </Form-item>
                            <div v-for="(item,index) in updatefilesname">                           
                                <Tag  type="dot" @on-close="delfile(index)" @click.native="showupload(index)" closable color="blue">{{item}}</Tag>                                                            
                            </div>                          
                        </div>
                    </Form>
                </Col>
            </Row>
        </Modal>
        <!-- 承保 -->
        <Modal v-model="underwriteModal" :mask-closable='closeable' width="600" title="承保" @on-ok="reInsure" :loading="loading">
            <Row class="common-box-body">
                <Col span="18" offset="3">                
                    <Form :model="underwrite"  :rules="ruleValidate">  
                        <FormItem label="承保单号" prop="policy_num">
                            <Input v-model="underwrite.policy_num" placeholder="请输入承保单号"></Input>
                        </FormItem>                                     
                        <Form-item label="承保时间" prop="underwrite_datetime">
                            <DatePicker type="date" v-model="underwrite.underwrite_datetime" @on-change="datachange($event,underwrite,'underwrite_date')"  placeholder="选择承保时间"></DatePicker>
                        </Form-item>
                    </Form>
                </Col>
            </Row>
        </Modal>
    </div>
</template>

<script>
import productTitle from '../../components/productTitle'
import { parteGetByName } from '../../api/parter'
import { getStsTokenWrite,getStsTokenRead } from '../../api/common';
import { getByName } from '../../api/employee'
import { getListByName } from '../../api/yun_org' 
import { getListUnderwrite , delPolicy , policyVisit , policyGetList ,policyReceipt , policyGetReceipt , policyGetVisit , policyEffect , policyGetEffect , policyUnderwrite , policyGetUnderwrite  } from '../../api/policy'
import { fileUpload } from '../../api/renewal'
import { formatTime } from '../../libs/time'
import debounce  from 'lodash.debounce'
export default {
    data() {
        return {
            closeable: false,
            loading: true,
            page: 1,
            pagesize: 10,
            listTotal:0,
            searchForm: {
                p: 1,
                pagesize: 10,
                policy_cid: [],
                yun_org_mid: '',
                appName: '',
                agent_name:'',
                underwite_year:'',
                underwite_yeartime:'',
                underwite_month:'',
                underwite_monthtime:'',
                daterangetime:[],
                type:'insure_date',
            },
            orglist:[],
            remoteloading:false,
            cname:'',
            oname:'',
            aname:'',
            proloading:false,
            comoptions:[],
            employeelist:[],
            tableloading:true,
            tableaction:true,  
            current:0,
            currentpage:1,
            effectModal:false,
            effect:{
                effect_datetime:'',
                effect_date:''
            },
            revisitModal:false,
            revisitInsure:{
                visit_datetime:'',
                visit_date:'',
                policy_id:''
            },
            receiptModal:false,
            receiptform:{
                receipt_datetime:'',
                receipt_date:'',
                policy_id:'',
                receipt_document:[]
            },
            renewalModal:false,
            renewalInsure:{

            },
            underwriteModal:false,
            underwrite:{
                policy_num:'',
                underwrite_datetime:'',
                underwrite_date:'',
                policy_id:''
            },
            files:{},
            updatefilesname:[],
            currentRow:{},
            columns1:[
                {
                    title: '公司名称',
                    key: 'cname',
                    align: 'center',
                },
                {
                    title: '保单号',
                    key: 'policy_num',
                    align:'center',
                    render:(h,params)=>{
                        return h('div',{
                            attrs:{
                                class:"a-link"
                            },
                            // on: {
                            //     click: () => {
                            //         this.toDetail(params.row.policy_id);
                            //     }
                            // }
                        },params.row.policy_num)
                    }
                },
                {
                    title: '投保人',
                    key: 'appName',
                    align:'center'
                },
                {
                    title: '保障计划',
                    key: 'name',
                    align:'center'
                },
                {
                    title: '规模保费',
                    key: 'premium',
                    align:'center'
                },
                {
                    title: '业务员',
                    key: 'agent_name',
                    align:'center'
                },
                {
                    title: '保单状态',
                    key: 'status',
                    align:'center',
                    render:(h,params)=>{
                        switch (params.row.status)
                        {
                            case 1:
                                return "预收件"
                                break;
                            case 2:
                                return "承保件"
                                break;
                            case 3:
                                return "契撤件"
                                break;
                            case 4:
                                return "停效件"
                                break;
                            case 5:
                                return "失效件"
                                break;
                            case 6:
                                return "解约件"
                                break;
                            case 7:
                                return "终止件"
                                break;
                            default:
                                return "承保件"
                        }
                    }
                },
            ],
            policylist:[

            ],
            effectValidate:{
                effect_datetime: [
                    { required: true, type: 'date', message: '请选择合同生效时间', trigger: 'change' }
                ],
            },
            ruleValidate: {                
                visit_datetime: [
                    { required: true, type: 'date', message: '请选择回访时间', trigger: 'change' }
                ],              
            },
            receiptValidate:{
                receipt_datetime: [
                    { required: true, type: 'date', message: '请选择回执时间', trigger: 'change' }
                ],          
            }        
        }
    },
    components: {
        productTitle
    },
    computed: {
        slidetoggle(){
            return this.$store.state.sildeshow
        },
    },
    mounted () {
        this.getList();
        this.orglistinit();
        this.cominit();
    },
    methods: {
        //上传之前
        handleUpload(file){
            
            new Promise((resolve, reject) => {
            let param = new FormData();
            param.append('file',file);
            
            console.log(file)
            fileUpload(param).then(response => {
                    console.log(response.data)
                    resolve();
                }).catch(error => {
                    reject(error);
                });
            });
            return false;
        },
        //时间转换
        datachange(date,obj,param){
            obj[param] = date
        },
        orglistinit(){
            new Promise((resolve, reject) => {
            let _params = {
                name:''
            }
            getListByName(_params).then(response => {
                    console.log(response.data)
                    if (response.data.err == 0) {               
                        this.orglist = response.data.data;
                    } else {
                        this.$Message.error(response.data.info);
                    }
                    resolve();
                }).catch(error => {
                    reject(error);
                });
            });
        },
        cominit(){
            new Promise((resolve, reject) => {
                let _params = {
                    name:''
                }
                parteGetByName(_params).then(response => {
                        console.log(response.data)
                        if (response.data.err == 0) {                           
                            this.comoptions = response.data.data;
                        } else {
                            this.$Message.error(response.data.info);
                        }
                        resolve();
                    }).catch(error => {
                        reject(error);
                    });
            });
        },
        //机构改变
        // orgchange(value){
        //     console.log(this.$refs)
        //     console.log(value)
        //     this.oname = value.label
        // },
        // oidremote(query){
        //     if (query !== '') {
        //         if(query == this.oname){
        //             this.searchForm.yun_org_mid = ''
        //             return
        //         }
        //         this.remoteloading = true;
        //         this.remoteorg(query)               
        //     } else {
        //         this.orglistinit();
        //     }
        // },
        // remoteorg:debounce(function (query) { 
            
        //     new Promise((resolve, reject) => {
        //     let _params = {
        //         name:query
        //     }
        //     getListByName(_params).then(response => {
        //             console.log(response.data)
        //             if (response.data.err == 0) {
        //                 this.remoteloading = false;                      
        //                 const list = response.data.data.map(item => {
        //                 return {
        //                         value: item.id,
        //                         label: item.shortn
        //                     };
        //                 });
        //                 this.orglist = list.filter(item => item.label.toLowerCase().indexOf(query.toLowerCase()) > -1);
        //             } else {
        //                 this.$Message.error(response.data.info);
        //             }
        //             resolve();
        //         }).catch(error => {
        //             reject(error);
        //         });
        //     });
        // },300),
        //删除回执资料
        delfile(index){
            console.log(index)
            this.updatefilesname.splice(index, 1);
            this.receiptform.receipt_document.splice(index,1);
        },
        //上传回执资料
        uploadChange(e){
            console.log(e)
            this.files={};
            var files = e.target.files[0];
            this.files = files;
            if(!/\.(gif|jpg|jpeg|png|bmp|GIF|JPG|PNG)$/.test(e.target.value)){
                this.$Message.error('图片类型必须是.gif,jpeg,jpg,png,bmp中的一种');
                return false;
            }
            new Promise((resolve, reject) => {
                getStsTokenWrite().then(response => {
                    if (response.data.err == 0) {
                        let r = new FileReader();
                        let sts = response.data.data.Credentials;
                        var client = new OSS.Wrapper({
                            region:'oss-cn-hangzhou',
                            accessKeyId:sts.AccessKeyId,
                            accessKeySecret:sts.AccessKeySecret,
                            stsToken:sts.SecurityToken,
                            bucket: 'kuaibao-imgs',
                            secure: true,
                        });
                        if(this.files){

                            let name = this.files.name;
                            let file = this.files;
                            var imageType = /^image\//;
                            //是否是图片
                            if (!imageType.test(file.type)) {
                                this.$Message.error("请选择图片！");
                                return;
                            }
                            client.multipartUpload(name, file, {

                            }).then((results) => {
                                console.log(results)
                                if(this.files.size > 102400){
                                    console.log("100")
                                    this.updatefilesname.push(results.name)
                                    let url = results.res.requestUrls[0].split('?')[0]
                                    this.receiptform.receipt_document.push(url)
                                }else{
                                    console.log("<100")
                                    if(results.name){
                                        this.updatefilesname.push(results.name)
                                        this.receiptform.receipt_document.push(results.url)
                                    }
                                }
                                
                            }).catch((err) => {
                                console.log(err)
                                this.$Message.error(err);
                            })
                        }
                    } else {
                        this.$Message.error(response.data.info);
                    }
                    resolve();
                }).catch(error => {
                    reject(error);
                });
            });
        },
        //获取回执信息
        getreceipt(){
            let params={
                policy_id:this.currentRow.policy_id
            }
            new Promise((resolve, reject) => {
                policyGetReceipt(params).then(response => {
                    if (response.data.err == 0) {
                        if(response.data.data.receipt_date){
                            this.receiptform.receipt_datetime = response.data.data.receipt_date
                            this.receiptform.receipt_date = response.data.data.receipt_date
                            this.receiptform.receipt_document = response.data.data.receipt_document
                            if(response.data.data.receipt_document&&this.receiptform.receipt_document.length > 0){
                                this.updatefilesname = response.data.data.receipt_document.map(function(item){
                                    let arry = item.split("/")
                                    return decodeURI(arry[(arry.length - 1)])  
                                })
                            }                           
                        }                        
                    } else {
                        this.$Message.error(response.data.info);
                    }
                    resolve();
                }).catch(error => {
                    reject(error);
                });
            });
        },
        //获取回访信息
        getvisit(){
            
            let params={
                policy_id:this.currentRow.policy_id
            }
            new Promise((resolve, reject) => {
                policyGetVisit(params).then(response => {
                    if (response.data.err == 0) {
                        if(response.data.data.visit_date){
                            this.revisitInsure.visit_datetime = response.data.data.visit_date
                            this.revisitInsure.visit_date = response.data.data.visit_date
                        }   
                    } else {
                        this.$Message.error(response.data.info);
                    }
                    resolve();
                }).catch(error => {
                    reject(error);
                });
            });
        },
        //获取合同生效时间
        geteffect(){
            let params={
                policy_id:this.currentRow.policy_id
            }
            new Promise((resolve, reject) => {
                policyGetEffect(params).then(response => {
                    if (response.data.err == 0) {
                        if(response.data.data.effect_date){
                            this.effect.effect_datetime = response.data.data.effect_date
                            this.effect.effect_date = response.data.data.effect_date
                        }   
                    } else {
                        this.$Message.error(response.data.info);
                    }
                    resolve();
                }).catch(error => {
                    reject(error);
                });
            });
        },
        //获取承保时间
        getunderwrite(){
            let params={
                policy_id:this.currentRow.policy_id
            }
            new Promise((resolve, reject) => {
                policyGetUnderwrite(params).then(response => {
                    if (response.data.err == 0) {
                        if(response.data.data.underwrite_date){
                            this.underwrite.underwrite_datetime = response.data.data.underwrite_date
                            this.underwrite.underwrite_date = response.data.data.underwrite_date
                            this.underwrite.policy_num = response.data.data.policy_num
                        }   
                    } else {
                        this.$Message.error(response.data.info);
                    }
                    resolve();
                }).catch(error => {
                    reject(error);
                });
            });
        },
        showupload(index){            
            window.open(this.receiptform.receipt_document[index])
        },
        toDetail(id){           
            this.$router.push({ name: 'underwrite_policy_update' ,params:{id:id}});
        },
        toUpdate(id){
            this.$router.push({ name: 'underwrite_policy_update' ,params:{id:id}});            
        },
        //编辑保单
        policyEdit(){
            console.log(this.currentRow.policy_id)
            this.toUpdate(this.currentRow.policy_id)
        },
        //搜索保险公司change事件
        // comchange(value){
        //     this.cname = value.label
        // },
        // remoteCom(query){
        //     if (query !== '') {
        //         if(query == this.cname){
        //             this.searchForm.cid = ''
        //             return
        //         }
        //         this.proloading = true;
        //         this.remotecom(query)               
        //     } else {
        //         this.remotecom('')
        //     }
        // },
        // remotecom:debounce(function (query) {             
        //     new Promise((resolve, reject) => {
        //         let _params = {
        //             name:query
        //         }
        //         parteGetByName(_params).then(response => {
        //                 console.log(response.data)
        //                 if (response.data.err == 0) {
        //                     this.proloading = false;                      
        //                     const list = response.data.data.map(item => {
        //                     return {
        //                             value: item.cid,
        //                             label: item.name
        //                         };
        //                     });
        //                     this.comoptions = list.filter(item => item.label.toLowerCase().indexOf(query.toLowerCase()) > -1);
        //                 } else {
        //                     this.$Message.error(response.data.info);
        //                 }
        //                 resolve();
        //             }).catch(error => {
        //                 reject(error);
        //             });
        //         });
        // },300),
        //远程请求业务员
        agentchange(value){
            this.aname = value.label
        },
        remoteemployee(query){
            if (query !== '') {
                if(query == this.aname){
                    this.searchForm.agent_name = ''
                    return
                }
                this.proloading = true;
                this.remoteagent(query)               
            } else {
                this.employeelist = [];
            }
        },
        remoteagent:debounce(function (query) {             
            new Promise((resolve, reject) => {
            let _params = {
                name:query
            }
            getByName(_params).then(response => {
                    console.log(response.data)
                    if (response.data.err == 0) {
                        // this.emplist = response.data.data 
                        this.proloading = false;                      
                        const list = response.data.data.map(item => {
                        return {
                                value: item.id,
                                label: item.name
                            };
                        });
                        this.employeelist = list.filter(item => item.label.toLowerCase().indexOf(query.toLowerCase()) > -1);
                    } else {
                        this.$Message.error(response.data.info);
                    }
                    resolve();
                }).catch(error => {
                    reject(error);
                });
            });
        },300),   
        //设置回访时间
        policyVisitBtn(){
            this.getvisit()
            this.revisitModal = !this.revisitModal;
        },
        //设置回执时间
        policyReceiptBtn(){
            this.getreceipt()
            this.receiptModal = !this.receiptModal;
        },
        //合同生效
        policyeffectBtn(){
            this.geteffect()
            this.effectModal = !this.effectModal
        },
        //承保
        policyUnderwriteBtn(){
            this.getunderwrite()  //policyGetUnderwrite
            this.underwriteModal = !this.underwriteModal
        },
        //时间转换
        datachange(date,obj,param){
            obj[param] = date
        },
        tableCurrentChange(currentRow,oldCurrentRow){
            console.log(currentRow)
            console.log(oldCurrentRow)
            this.tableaction = false;
            this.currentRow = currentRow
            console.log(this.currentRow)
        },
        // 搜索
        search() {
            this.getList();
        },
        // 获取承保单列表
        getList() {    
            this.tableloading = true    
            this.tableaction = true      
            new Promise((resolve, reject) => {
                policyGetList(this.searchForm).then(response => {
                    if (response.data.err == 0) {
                        this.policylist = response.data.data.list;
                        this.listTotal = response.data.data.total;
                        this.tableloading = false
                    } else {
                        this.$Message.error(response.data.info);
                    }
                    resolve();
                }).catch(error => {
                    reject(error);
                });
            });
        },
        // 页码改变
        pageChange(page) {
            this.page = page
            this.searchForm.p = page
            this.getList()
        },
        // 每页条数改变
        pageSizeChange(pagesize) {
            this.pagesize = pagesize
            this.searchForm.pagesize = pagesize
            this.getList();
        },
        del(param) {
            new Promise((resolve, reject) => {
                delPolicy(param).then(response => {
                    if (response.data.err == 0) {
                        this.getList();
                        this.$Message.success(response.data.info);  
                    } else {
                        this.$Message.error(response.data.info);
                    }
                    resolve();
                }).catch(error => {
                    reject(error);
                });
            });
        },
        //新增承保保单
        createPloicy() {
            this.$router.push({ name: 'underwrite_policy_create' });
        },
        // 删除时弹出对话框
        policyDel() {
            this.$Modal.confirm({
                title: '提示',
                content: '是否要删除该保单?',
                onOk: () => {
                    let _params = {
                        'policy_id': this.currentRow.policy_id
                    }
                    this.del(_params);
                },
            });
        },
        // 回访
        visitInsure() {
            this.revisitInsure.policy_id = this.currentRow.policy_id
            new Promise((resolve, reject) => {
                policyVisit(this.revisitInsure).then(response => {
                    if (response.data.err == 0) {
                        this.getList();
                        this.$Message.success(response.data.info);
                        this.revisitModal = false;
                        this.loading = true;
                    } else {
                        this.$Message.error(response.data.info);
                        setTimeout(() => {
                            this.loading = false;
                            this.$nextTick(() => {
                                this.loading = true;
                            });
                        }, 2000);
                    }
                    resolve();
                }).catch(error => {
                    reject(error);
                });
            });
        },
        //回执
        receiptok(){
             this.$refs['receiptform'].validate((valid) => {
                if (valid) {
                    this.receiptform.policy_id = this.currentRow.policy_id
                    new Promise((resolve, reject) => {
                        policyReceipt(this.receiptform).then(response => {
                            if (response.data.err == 0) {
                                this.getList();
                                this.$Message.success(response.data.info);
                                this.receiptModal = false;
                                this.loading = true;
                            } else {
                                this.$Message.error(response.data.info);
                                setTimeout(() => {
                                    this.loading = false;
                                    this.$nextTick(() => {
                                        this.loading = true;
                                    });
                                }, 2000);
                            }
                            resolve();
                        }).catch(error => {
                            reject(error);
                        });
                    });
                }
            })
            
        },
        //合同生效时间
        effectok(){
            this.$refs['effect'].validate((valid) => {
                if (valid) {
                    this.effect.policy_id = this.currentRow.policy_id
                    new Promise((resolve, reject) => {
                        policyEffect(this.effect).then(response => {
                            if (response.data.err == 0) {
                                this.getList();
                                this.$Message.success(response.data.info);
                                this.effectModal = false;
                                this.loading = true;
                            } else {
                                this.$Message.error(response.data.info);
                                setTimeout(() => {
                                    this.loading = false;
                                    this.$nextTick(() => {
                                        this.loading = true;
                                    });
                                }, 2000);
                            }
                            resolve();
                        }).catch(error => {
                            reject(error);
                        });
                    });
                }
            })
        },
        renewalInsureok(){

        },
        // 承保
        reInsure() {
            this.underwrite.policy_id = this.currentRow.policy_id
            new Promise((resolve, reject) => {
                policyUnderwrite(this.underwrite).then(response => {
                    if (response.data.err == 0) {
                        this.getList();
                        this.$Message.success(response.data.info);
                        this.underwriteModal = false;
                        this.loading = true;
                    } else {
                        this.$Message.error(response.data.info);
                        setTimeout(() => {
                            this.loading = false;
                            this.$nextTick(() => {
                                this.loading = true;
                            });
                        }, 2000);
                    }
                    resolve();
                }).catch(error => {
                    reject(error);
                });
            });
        }
    }
}
</script>
